﻿using System;

namespace CSharp_1209.Exam2
{
    internal class Person
    {
        private string _firstName;
        private string _lastName;
        private string _emailAddress;
        private DateTime _dayOfBirth;

        private CSharp_1209.Library.Book b;
        public string FirstName
        {
            get { return _firstName; }
            set { _firstName = value; }
        }

        public string LastName
        {
            get { return _lastName; }
            set { _lastName = value; }
        }

        public string EmailAddress
        {
            get { return _emailAddress; }
            set { _emailAddress = value; }
        }

        public DateTime DayOfBirth
        {
            get { return _dayOfBirth; }
            set { _dayOfBirth = value; }
        }

        public bool IsBirthday()
        {
            return (DateTime.Today.Day == _dayOfBirth.Day && DateTime.Today.Month == _dayOfBirth.Month);
        }

        public bool Adult
        {
            get
            {
                DateTime today = DateTime.Today;

                //if (today.Year - _dayOfBirth.Year > 18)
                //    return true;
                //else if (today.Year - _dayOfBirth.Year == 18)
                //{
                //    if (today.Month > _dayOfBirth.Month)
                //        return true;
                //    else if (today.Month == _dayOfBirth.Month)
                //    {
                //        if (today.Day >= _dayOfBirth.Day)
                //            return true;
                //    }
                //}

                bool result = (today.Year - _dayOfBirth.Year - 18) * 366 +
                              (today.Month - _dayOfBirth.Month) * 31 + (today.Day - _dayOfBirth.Day) >= 0;
                return result;
            }
        }

        public string SunSign
        {
            get
            {
                int[,] sign =
                    {
                        {21, 3, 20, 4}, {21, 4, 20, 5}, {21, 5, 21, 6},
                        {22, 6, 22, 7}, {23, 7, 22, 8}, {23, 8, 22, 9},
                        {23, 9, 23, 10}, {24, 10, 21, 11}, {22, 11, 21, 12},
                        {22, 12, 19, 1}, {20, 1, 18, 2}, {19, 2, 20, 3}
                    };
                string[] nameSign =
                    {
                        "Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo", "Libra", "Scorpio", "Sagittarius",
                        "Capricornus", "Aquarius", "Pisces"
                    };
                int day = _dayOfBirth.Day, month = _dayOfBirth.Month;

                for (int i = 0; i < 12; i++)
                    if ((month == sign[i, 1] && day >= sign[i, 0])
                        || (month == sign[i, 3] && day <= sign[i, 2]))
                        return nameSign[i];

                return "Other";
            }
        }

        public Person()
        {
            this._firstName = "";
            this._lastName = "";
            this._emailAddress = "";
            this._dayOfBirth = DateTime.Today;
        }

        public Person(string firstName, string lastname, string email)
        {
            this._firstName = firstName;
            this._lastName = lastname;
            this._emailAddress = email;
        }

        public Person(string firstName, string lastname, DateTime day)
        {
            this._firstName = firstName;
            this._lastName = lastname;
            this._dayOfBirth = day;
        }

        public Person(string firstName, string lastName, string email, DateTime day)
        {
            this._firstName = firstName;
            this._lastName = lastName;
            this._emailAddress = email;
            this._dayOfBirth = day;
        }

        public bool Age
        {
            get
            {
                bool flag = false;

                if ((DateTime.Today.Year - _dayOfBirth.Year) > 18)
                {
                    flag = true;
                }
                else if ((DateTime.Today.Year - _dayOfBirth.Year) < 18)
                {
                    flag = false;
                }
                else
                {
                    if (_dayOfBirth.Month < DateTime.Today.Month)
                        flag = true;
                    else if ((_dayOfBirth.Month == DateTime.Today.Month) && (_dayOfBirth.Day <= DateTime.Today.Day))
                        flag = true;
                    else
                        flag = false;
                }

                return flag;
            }
        }

        public string OtherSunSign
        {
            get
            {
                string sunsign = "";
                switch (_dayOfBirth.Month)
                {
                    case 1:
                        if (_dayOfBirth.Day <= 19)
                            sunsign = "Capricornus";
                        else
                            sunsign = "Aquarius";
                        break;

                    case 2:
                        if (_dayOfBirth.Day <= 18)
                            sunsign = "Aquarius";
                        else
                            sunsign = "Pisces";
                        break;

                    case 3:
                        if (_dayOfBirth.Day <= 20)
                            sunsign = "Pisces";
                        else
                            sunsign = "Aries";
                        break;

                    case 4:
                        if (_dayOfBirth.Day <= 20)
                            sunsign = "Aries";
                        else
                            sunsign = "Taurus";
                        break;

                    case 5:
                        if (_dayOfBirth.Day <= 20)
                            sunsign = "Aries";
                        else
                            sunsign = "Gemini";
                        break;

                    case 6:
                        if (_dayOfBirth.Day <= 21)
                            sunsign = "Gemini";
                        else
                            sunsign = "Cancer";
                        break;

                    case 7:
                        if (_dayOfBirth.Day <= 22)
                            sunsign = "Cancer";
                        else
                            sunsign = "Leo";
                        break;

                    case 8:
                        if (_dayOfBirth.Day <= 22)
                            sunsign = "Leo";
                        else
                            sunsign = "Virgo";
                        break;

                    case 9:
                        if (_dayOfBirth.Day <= 22)
                            sunsign = "Virgo";
                        else
                            sunsign = "Libra";
                        break;

                    case 10:
                        if (_dayOfBirth.Day <= 23)
                            sunsign = "Libra";
                        else
                            sunsign = "Scorpio";
                        break;

                    case 11:
                        sunsign = _dayOfBirth.Day <= 21 ? "Scorpio" : "Sagittarius";
                        break;

                    case 12:
                        if (_dayOfBirth.Day <= 21)
                            sunsign = "Sagittarius";
                        else
                            sunsign = "Capricornus";
                        break;

                }

                if ((_dayOfBirth.Month == 1 && _dayOfBirth.Day <= 19) || (_dayOfBirth.Month == 12 && _dayOfBirth.Day >= 22))
                    return "Ma Ket";
                return sunsign;
            }
        }

        private void Test()
        {
            Person p = new Person("Firstname", "Lastname", "email@email.com", new DateTime(1995, 8, 7));

            Console.WriteLine("Your Firstname : {0}", p.FirstName);
            Console.WriteLine("Your Lastname : {0}", p.LastName);
            Console.WriteLine("Your Email : {0}", p.EmailAddress);
            Console.WriteLine("Your Birthday : {0}", p.DayOfBirth.ToShortDateString());

            Console.WriteLine("You're adult : {0}", p.Adult);
            Console.WriteLine("Today is your birthday : {0}", p.IsBirthday());
            Console.WriteLine("Your sunsign : {0}", p.SunSign);
        }
    }


}
